from rest_framework.renderers import JSONRenderer


class MyJSONRenderer(JSONRenderer):

    def render(self, data, accepted_media_type=None, renderer_context=None):
        # 只要方法中使用 return Pesponse(data)时
        # render()方法会被调用 ，将data转化为json
        # data相当于res
        # a = data
        # if not data:
        #     code = 200
        #     msg = '请求成功'
        #     result = {}
        # if data and isinstance(data, dict):
        #     count = data.pop('count', 200)
        #
        #     result = data.pop('data', data)
        #
        # if not isinstance(data, dict):
        #     code = 200
        #
        #     result = data
        # #  将全部的响应状态码改为200
        # # renderer_context['response'].status_code = 200
        # res = {
        #     'count': count,
        #
        #     'data': data,
        #
        # }
        return super().render(data)